<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
			<el-form-item label="申请用户" prop="userNickName">
				<el-input v-model="queryParams.userNickName" placeholder="请输入申请用户" clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="邀请人" prop="inviterNickName">
				<el-input v-model="queryParams.inviterNickName" placeholder="请输入邀请人" clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="门店名称" prop="name">
				<el-input v-model="queryParams.name" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="手机号码" prop="tel">
				<el-input v-model="queryParams.tel" placeholder="请输入手机号码" clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="地址" prop="address">
				<el-input v-model="queryParams.address" placeholder="请输入地址" clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="类型" prop="type">
				<el-select v-model="queryParams.type" placeholder="请选择类型" clearable @change="handleQuery">
					<el-option label="回收门店" :value="1"></el-option>
					<el-option label="抵扣门店" :value="2"></el-option>
					<el-option label="消费补贴门店" :value="3"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<!-- <el-col :span="1.5">
				<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['biz:storeApplyRecord:add']">新增</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['biz:storeApplyRecord:edit']">修改</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['biz:storeApplyRecord:remove']">删除</el-button>
			</el-col> -->
			<el-col :span="1.5">
				<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['biz:storeApplyRecord:export']">导出</el-button>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column label="主键" align="center" prop="id" />
			<el-table-column label="提现金额" align="center" prop="withdrawalAmount" />
			<el-table-column label="申请用户" align="center" prop="username" />
			<el-table-column label="申请用户ID" align="center" prop="userId" />
			<el-table-column label="原因" align="center" prop="reason" />
			<el-table-column label="创建时间" align="center" prop="createTime" />
			<el-table-column label="状态" align="center" prop="statusName" />
			<el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button v-if="scope.row.status == 1" size="mini" type="text" icon="el-icon-edit" @click="deductionWithdrawal(scope.row)" v-hasPermi="['biz:storeApplyRecord:remove']">审核</el-button>
				
				</template>
			</el-table-column>
		</el-table>

		<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

	</div>
</template>

<script>
import {
	deductionWithdrawal,
	listWithdrawal,
} from '@/api/biz/drawMoneyApplyRecord';

export default {
	name: 'drawMoneyApplyRecord',
	data() {
		return {
			// 遮罩层
			loading: true,
			// 选中数组
			ids: [],
			// 非单个禁用
			single: true,
			// 非多个禁用
			multiple: true,
			// 显示搜索条件
			showSearch: true,
			// 总条数
			total: 0,
			// biz_门店申请记录表格数据
			list: [],
			// 弹出层标题
			title: '',
			// 是否显示弹出层
			open: false,
			// 查询参数
			queryParams: {
				pageNum: 1,
				pageSize: 10,
				type: null,
				categoryId: null,
				userId: null,
				name: null,
				tel: null,
				address: null,
				latitude: null,
				longitude: null,
				openTime: null,
				imgUrl: null,
				logoUrl: null,
				content: null,
				status: null,
				rejetctReason: null,
				deductionPercentage: null,
				inviteCode: null,
			},
			// 表单参数
			form: {},
			// 表单校验
			rules: {},
		};
	},
	created() {
		this.getList();
	},
	methods: {
		/** 查询biz_门店申请记录列表 */
		getList() {
			this.loading = true;
			listWithdrawal(this.queryParams).then((response) => {
				this.list = response.rows;
				this.total = response.total;
				this.loading = false;
			});
		},
		// 取消按钮
		cancel() {
			this.open = false;
			this.reset();
		},
		// 表单重置
		reset() {
			this.form = {
				id: null,
				type: null,
				categoryId: null,
				userId: null,
				name: null,
				tel: null,
				address: null,
				latitude: null,
				longitude: null,
				openTime: null,
				imgUrl: null,
				logoUrl: null,
				content: null,
				status: 0,
				rejetctReason: null,
				createByName: null,
				createById: null,
				createTime: null,
				updateByName: null,
				updateById: null,
				updateTime: null,
				deleted: null,
				remark: null,
				deductionPercentage: null,
				inviteCode: null,
			};
			this.resetForm('form');
		},
		/** 搜索按钮操作 */
		handleQuery() {
			this.queryParams.pageNum = 1;
			this.getList();
		},
		/** 重置按钮操作 */
		resetQuery() {
			this.resetForm('queryForm');
			this.handleQuery();
		},
		// 多选框选中数据
		handleSelectionChange(selection) {
			this.ids = selection.map((item) => item.id);
			this.single = selection.length !== 1;
			this.multiple = !selection.length;
		},
		/** 新增按钮操作 */
		handleAdd() {
			this.reset();
			this.open = true;
			this.title = '添加biz_门店申请记录';
		},
		/** 修改按钮操作 */
		handleUpdate(row) {
			this.reset();
			const id = row.id || this.ids;
			getStoreApplyRecord(id).then((response) => {
				this.form = response.data;
				this.open = true;
				this.title = '修改biz_门店申请记录';
			});
		},
		/** 提交按钮 */
		submitForm() {
			this.$refs['form'].validate((valid) => {
				if (valid) {
					if (this.form.id != null) {
						updateStoreApplyRecord(this.form).then((response) => {
							this.$modal.msgSuccess('修改成功');
							this.open = false;
							this.getList();
						});
					} else {
						addStoreApplyRecord(this.form).then((response) => {
							this.$modal.msgSuccess('新增成功');
							this.open = false;
							this.getList();
						});
					}
				}
			});
		},
		deductionWithdrawal(row) {
			this.$confirm('请选择通过审核或者不通过', '审核', {
				distinguishCancelAndClose: true,
				confirmButtonText: '通过',
				cancelButtonText: '不通过',
			})
				.then(() => {
					const params = {
						id: row.id,
						approved: true,
						reason:'1'
					};
					deductionWithdrawal(params).then((response) => {
						this.$message.success('操作成功');
						this.getList();
					});
				})
				.catch((action) => {
					if (action === 'cancel') {
						const params = {
							id: row.id,
							approved: false,
							reason:'2'
						};
						deductionWithdrawal(params).then((response) => {
							this.$message.success('操作成功');
							this.getList();
						});
					}
				});
		},
		/** 删除按钮操作 */
		handleDelete(row) {
			const ids = row.id || this.ids;
			this.$modal
				.confirm(
					'是否确认删除biz_门店申请记录编号为"' + ids + '"的数据项？'
				)
				.then(function () {
					return delStoreApplyRecord(ids);
				})
				.then(() => {
					this.getList();
					this.$modal.msgSuccess('删除成功');
				})
				.catch(() => {});
		},
		/** 导出按钮操作 */
		handleExport() {
			this.download(
				'biz/storeApplyRecord/export',
				{
					...this.queryParams,
				},
				`storeApplyRecord_${new Date().getTime()}.xlsx`
			);
		},
	},
};
</script>
